package com.lucian.ge.controller.shopportal;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lucian.ge.auth.controller.GetAuthController;
import com.lucian.ge.service.shop.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lucian.ge.comman.model.ResultMap;

import java.util.List;
import java.util.Map;

/**
 * Created by Lucicol on 2019/6/20.
 */
@Api(value = "ProductController", description = "product-商品接口")

@RestController
@RequestMapping("/product")
public class ProductController {

    private final ResultMap resultMap;

    @Autowired
    public ProductController(ResultMap resultMap) {
        this.resultMap = resultMap;
    }

    @Autowired(required=false)
    private ProductService productService;

    /**
     * 获得商品列表
     * @param categoryId
     * @return
     */
    @ApiOperation(value="获得商品列表", notes="")
    @GetMapping("/get_productlist")
    @ResponseBody
    public ResultMap get_productList (
            @RequestParam(value = "categoryId",required = false)Integer categoryId
    ) {
        List<Map<String, String>> productList = productService.getProductList(categoryId);
        System.out.println(productList);
        return resultMap.success().code(200).message("获得商品列表成功").token("").res(productList).data(null);
    }

    /**
     * 获得商品
     * @param id
     * @return
     */
    @ApiOperation(value="获得商品", notes="")
    @GetMapping("/get_product")
    @ResponseBody
    public ResultMap get_product (
            @RequestParam(value = "id",required = false)Integer id
    ) {
        Map<String, String> product = productService.getProduct(id);
        System.out.println(product);
        return resultMap.success().code(200).message("获得商品成功").token("").res(product).data(null);
    }

}
